﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace ZLCMS.Web.SystemManage.Control
{
    public partial class CheckBoxControl : System.Web.UI.UserControl
    {
        public CheckBoxList DataList { get { return cbl_list; }  }

        public string SelectedValue
        {
            get { return GetSelectedValue(); }

            set
            {
                SetSelectedValue(value);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 返回选中的项，以逗号','分隔
        /// </summary>
        /// <returns>以逗号','分隔的结果串</returns>
        protected string GetSelectedValue()
        {
            string strSelectValue = "";

            foreach (ListItem item in cbl_list.Items)
            {
                if (item.Selected)
                {
                    strSelectValue += item.Value + ",";
                }
            }
            return strSelectValue;
        }
        
        protected void SetSelectedValue(string valueList)
        {
            valueList = "," + valueList + ",";

            foreach (ListItem item in cbl_list.Items)
            {
                if (valueList.Contains("," + item.Value + ","))
                {
                    item.Selected = true;
                }
            }
        }
    }
}